package com.hyk.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyk.domain.CoinConfig;
import com.hyk.dto.R;
import com.hyk.service.CoinConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "钱包配置控制器")
@RequestMapping("/coinConfigs")
public class CoinConfigController {

    @Resource
    private CoinConfigService coinConfigService;

    @GetMapping("/info/{coinId}")
    @ApiOperation("通过id查询钱包配置信息")
    public R<CoinConfig> info(@PathVariable("coinId") Long coinId){
        QueryWrapper<CoinConfig> wrapper = new QueryWrapper<>();
        wrapper.eq("id",coinId);
        return R.ok(coinConfigService.getOne(wrapper));
    }

    @PatchMapping
    @ApiOperation("编辑钱包配置信息")
    public R updateCoinConfig(@RequestBody CoinConfig coinConfig){
        boolean update = coinConfigService.saveOrUpdateConfig(coinConfig);
        if (update) {
            return R.ok();
        }
        return R.fail();
    }

}
